﻿<UserControl x:Class="MContracts.View.ActsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:MContracts.Classes.Converters"
             xmlns:Controls="clr-namespace:MContracts.Controls" mc:Ignorable="d" 
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             
             d:DesignHeight="300" d:DesignWidth="800" DataContext="{Binding}" DataContextChanged="UserControl_DataContextChanged">
    
    <UserControl.Resources>


      <converters:ActSignedToImageConverter x:Key="ActSignedToImageConverter" />
    </UserControl.Resources>

    <!--<Expander IsExpanded="{Binding IsMaximized, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Background="{StaticResource Expander-Background-Act-Brush}">-->
    <Expander IsExpanded="true" Background="{StaticResource Expander-Background-Act-Brush}">
    <!--<Expander IsExpanded="{Binding IsMaximized, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">-->
        <Expander.Resources>
            <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" TrueVisibility="Visible" FalseVisibility="Collapsed" />
        </Expander.Resources>
        
        <Expander.Header>
            <WrapPanel>
                <Image Source="/MContracts;component/Images/text_editor.png" Width="30"></Image>
                <Label>Акты</Label>
                <Controls:CommandsControl x:Name="commandsControl" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource AncestorType=Expander}, Converter={StaticResource BoolToVisibilityConverter}}"></Controls:CommandsControl>
            </WrapPanel>
        </Expander.Header>
        <Expander.Content>
            <!--<Border BorderThickness="4" CornerRadius="4" Padding="2">-->
                <Border BorderThickness="4" CornerRadius="4" Padding="2" Background="{StaticResource ResourceKey=Expander-Background-Brush}">

                    <StackPanel>
                    <!--    <StackPanel Orientation="Horizontal" Margin="3">
                        <Button ToolTip="Создать акт" Command="{Binding CreateActCommand}">
                            <Image Source="/MContracts;component/Resources/act_add.png" />
                        </Button>
                        <Button ToolTip="Редактировать акт" Command="{Binding EditActCommand}">
                            <Image Source="/MContracts;component/Resources/act_edit.png" />
                        </Button>
                        <Button ToolTip="Удалить акт" Margin="3" Command="{Binding DeleteActCommand}">
                            <Image Source="/MContracts;component/Resources/act_delete.png" />
                        </Button>
                    </StackPanel>-->
                    <DockPanel LastChildFill="True">
                        <StackPanel Width="1" DockPanel.Dock="Left"/>
                        <StackPanel Width="1" DockPanel.Dock="Right"/>
                        <StackPanel>
                        <StackPanel>
                            <Label Content="Календарный план" />
                            <ComboBox Margin="3,0,3,0" ItemsSource="{Binding Schedulecontracts}" SelectedItem="{Binding SelectedSchedule, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectionChanged="ComboBox_SelectionChanged" />
                        </StackPanel>
                        
                        <StackPanel DockPanel.Dock="Top">
                           <CheckBox Content="автоматически увеличивать на единицу номер акта" IsChecked="{Binding AutoIncNums, Mode=TwoWay}" Margin="5,7"/>
                        </StackPanel>
                            <telerik:RadGridView CanUserInsertRows="False" SelectionMode="Single" 
                                             SelectedItem="{Binding SelectedAct, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                             SelectionUnit="FullRow" CanUserDeleteRows="False" MaxHeight="600" 
                                             Margin="3" ItemsSource="{Binding Path=ActsBindingList, UpdateSourceTrigger=PropertyChanged}" 
                                             CanUserSortColumns="False" ShowColumnHeaders="True"
                                             AutoGenerateColumns="False" x:Name="ActsDG" ShowGroupPanel="False"
                                             ShowColumnFooters="True"
                                             RowIndicatorVisibility="Collapsed"
                                             IsReadOnly="True">
                                <telerik:RadGridView.Columns>
                                    <telerik:GridViewDataColumn Width="Auto" IsReadOnly="True" >
                                        <telerik:GridViewDataColumn.CellTemplate>
                                            <DataTemplate>
                                                <Image Width="20" Height="20" Margin="2" ToolTip="{Binding Path=Signedstring}" Source="{Binding Path=Issigned, Converter={StaticResource ActSignedToImageConverter}}"/>
                                            </DataTemplate>
                                        </telerik:GridViewDataColumn.CellTemplate>
                                    </telerik:GridViewDataColumn>
                                    <telerik:GridViewDataColumn Width="Auto" DataMemberBinding="{Binding Num, Mode=OneWay}" Header="№">
                                        <telerik:GridViewDataColumn.AggregateFunctions>
                                            <telerik:CountFunction Caption="Актов:" />
                                        </telerik:GridViewDataColumn.AggregateFunctions>
                                     </telerik:GridViewDataColumn> 
                                    <telerik:GridViewDataColumn Width="Auto" DataMemberBinding="{Binding Signdate, StringFormat='{}{0:d}', Mode=OneWay}" Header="Дата подписания"/>
                                    <telerik:GridViewDataColumn Width="Auto" DataMemberBinding="{Binding StagesNumbers, Mode=OneWay}" Header="Этапы"/>
                                    <telerik:GridViewDataColumn Width="Auto" TextAlignment="Right"  UniqueName="PricePure" FooterTextAlignment="Right">
                                        <telerik:GridViewColumn.Header>
                                            <Binding Path="StagePriceWithNoNDSColumnTitle"/>
                                        </telerik:GridViewColumn.Header>
                                        <telerik:GridViewDataColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Margin="2" Text="{Binding ActMoney.PureValue, Mode=OneWay, ConverterCulture=ru-ru, StringFormat=N2, TargetNullValue=0, FallbackValue=0}"  VerticalAlignment="Center" HorizontalAlignment="Stretch" TextAlignment="Right"/>
                                            </DataTemplate>
                                        </telerik:GridViewDataColumn.CellTemplate>
                                        <telerik:GridViewDataColumn.AggregateFunctions>
                                           <telerik:SumFunction SourceField="ActMoney.Factor.National.PureValue" ResultFormatString="{}{0:N2}"/>
                                        </telerik:GridViewDataColumn.AggregateFunctions>
                                    </telerik:GridViewDataColumn>

                                    <telerik:GridViewDataColumn Width="Auto" TextAlignment="Right"  FooterTextAlignment="Right" >
                                        <telerik:GridViewDataColumn.Header>
                                            <Binding Path="StagePriceWithNDSColumnTitle"/>
                                        </telerik:GridViewDataColumn.Header>
                                        <telerik:GridViewDataColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Margin="2" Text="{Binding ActMoney.PriceWithNdsValue, Mode=OneWay, ConverterCulture=ru-ru, StringFormat=N2, TargetNullValue=0, FallbackValue=0}"   VerticalAlignment="Center" HorizontalAlignment="Stretch" TextAlignment="Right"/>
                                            </DataTemplate>
                                        </telerik:GridViewDataColumn.CellTemplate>

                                        <telerik:GridViewDataColumn.AggregateFunctions>
                                            <telerik:SumFunction SourceField="ActMoney.Factor.National.PriceWithNdsValue" ResultFormatString="{}{0:N2}"/>
                                        </telerik:GridViewDataColumn.AggregateFunctions>
                                    </telerik:GridViewDataColumn>
                                    <telerik:GridViewDataColumn Width="Auto" TextAlignment="Right"  FooterTextAlignment="Right">
                                        <telerik:GridViewDataColumn.Header>
                                            <Binding Path="NDSColumnTitle" />
                                        </telerik:GridViewDataColumn.Header>
                                        <telerik:GridViewDataColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Margin="2" Text="{Binding ActMoney.NdsValue, Mode=OneWay, StringFormat=N2,  ConverterCulture=ru-ru, TargetNullValue=0, FallbackValue=0}" VerticalAlignment="Center" HorizontalAlignment="Stretch" TextAlignment="Right"/>
                                            </DataTemplate>
                                        </telerik:GridViewDataColumn.CellTemplate>
                                        <telerik:GridViewDataColumn.AggregateFunctions>
                                                    <telerik:SumFunction SourceField="ActMoney.Factor.National.NdsValue" ResultFormatString="{}{0:N}"/>
                                        </telerik:GridViewDataColumn.AggregateFunctions>
                                    </telerik:GridViewDataColumn>
                                    <telerik:GridViewDataColumn Width="Auto" TextAlignment="Right"  FooterTextAlignment="Right">
                                        <telerik:GridViewDataColumn.Header>
                                            <Binding Path="PrepaymentColumnTitle" />
                                        </telerik:GridViewDataColumn.Header>
                                        <telerik:GridViewDataColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Margin="2" Text="{Binding CreditedMoneyModel.PriceWithNdsValue, Mode=OneWay, StringFormat=N2, TargetNullValue=0, FallbackValue=0}" VerticalAlignment="Center" HorizontalAlignment="Stretch" TextAlignment="Right"/>
                                            </DataTemplate>
                                        </telerik:GridViewDataColumn.CellTemplate>
                                        <telerik:GridViewDataColumn.AggregateFunctions>
                                           <telerik:SumFunction SourceField="CreditedMoneyModel.Factor.National.PriceWithNdsValue" ResultFormatString="{}{0:C}" />
                                        </telerik:GridViewDataColumn.AggregateFunctions>
                                    </telerik:GridViewDataColumn>
                                    <telerik:GridViewDataColumn Width="Auto" TextAlignment="Right"   FooterTextAlignment="Right">
                                        <telerik:GridViewDataColumn.Header>
                                            <Binding Path="TransferColumnTitle" />
                                        </telerik:GridViewDataColumn.Header>
                                        <telerik:GridViewDataColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Margin="2" Text="{Binding TransferSumMoney.PriceWithNdsValue, Mode=OneWay, StringFormat=N2, TargetNullValue=0, FallbackValue=0}" VerticalAlignment="Center" HorizontalAlignment="Stretch" TextAlignment="Right"/>
                                            </DataTemplate>
                                        </telerik:GridViewDataColumn.CellTemplate>
                                        <telerik:GridViewDataColumn.AggregateFunctions>
                                            <telerik:SumFunction SourceField="TransferSumMoney.Factor.National.PriceWithNdsValue" ResultFormatString="{}{0:C}" />
                                        </telerik:GridViewDataColumn.AggregateFunctions>
                                    </telerik:GridViewDataColumn>
                                </telerik:RadGridView.Columns>
                            </telerik:RadGridView>

                        </StackPanel>
                    </DockPanel>
                </StackPanel>
                
            </Border>
        </Expander.Content>
    </Expander>
</UserControl>
